#!/bin/sh
#
# Attempt to strip the path
#
TestName="strip-test"
JobName=stripTest
. scripts/functions

scripts/cleanup
scripts/copy-strip-confs

# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data data/small.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list


# Now, strip the first 4 parts of the path (which is what
#   the backup will do and put the result in rpath
rpath="`echo ${BackupDirectory} | cut -f5- -d'/'`"
print_debug "orig path =$BackupDirectory"
print_debug "strip path=$rpath"

change_jobname NightlySave $JobName
start_test

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@#
@# Do a backup
@#
@$out ${cwd}/tmp/log1.out
@#setdebug level=150 dir
@#setdebug level=150 storage=FileStorage
setdebug level=100 client=$CLIENT
label storage=FileStorage pool=Default volume=TestVolume001
run job=$JobName storage=FileStorage pool=Default yes
wait
messages
quit
END_OF_DATA


run_susan

rm -rf ${cwd}/tmp/susan-restores

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@#
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
@#setdebug level=50 client=$CLIENT
restore where=${cwd}/tmp/susan-restores select all storage=FileStorage done
yes
wait
messages
quit
END_OF_DATA

run_bconsole

check_for_zombie_jobs storage=FileStorage
stop_susan

check_two_logs
#
if test "$debug" -eq 1 ; then
   diff -ur ${BackupDirectory} ${tmp}/susan-restores/${rpath}
else
   diff -r ${BackupDirectory} ${tmp}/susan-restores/${rpath} 2>&1 >/dev/null
fi
dstat=$?

end_test
